# -*- coding: utf-8 -*-
'''
模块：生意通-工具中心-直通车
输入：cookie,hotel_id,hotel_name
输出：

'''
import requests
import json
import datetime
import pipelines
from fcs import url_request

def main(cookies,hotel_id,hotel_name):

    url="http://syt.ctrip.com/api/roomTypeDetailAjax/getBiddingRequestRecordsByPage?hostType=Ebooking"
    header={
        'Content-Type':'application/x-www-form-urlencoded;charset=UTF-8'
    }

    data={
        'pageIndex':1
    }
    # con=requests.post(url=url,cookies=cookies,headers=header,data=data).text
    while True:
        try:
            con=url_request.post_url_requests(url=url,cookies=cookies,headers=header,data=data)
            json_data=json.loads(con)['data']['biddingLogs']
            break
        except:
            continue
    for i in json_data:
        item = {}
        submitTime=i['submitTime']
        startDate=i['startDate']
        endDate=i['endDate']
        biddingFG=i['biddingFG']
        biddingPP=i['biddingPP']
        submitName=i['submitName']
        stateDesc=i['stateDesc']

        item.update(table='a_ota_back_hotel_bidding')
        item.update(HotelId=hotel_id)
        item.update(HotelName=hotel_name)
        item.update(submitTime=submitTime)
        item.update(startDate=startDate)
        item.update(endDate=endDate)
        item.update(biddingFG=biddingFG)
        item.update(biddingPP=biddingPP)
        item.update(submitName=submitName)
        item.update(stateDesc=stateDesc)
        item.update(create_time=datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))

        pipelines.process_item(item)



